// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   BalanceProcessor.java

package com.boci.clientapp.balance.processor;

import com.boci.clientapp.balance.vo.BalanceDetailVO;
import com.boci.clientapp.balance.vo.BalanceVO;
import com.boci.common.constant.RequestTypeConst;
import com.boci.common.processor.AbstractResponseProcessor;
import com.boci.common.vo.ResponseVO;
import java.util.ArrayList;
import org.w3c.dom.*;

public class BalanceProcessor extends AbstractResponseProcessor
{

    public BalanceProcessor(String pXML, String pReqType)
        throws Exception
    {
        super(pXML, pReqType, "BALANCE.ERROR_");
    }

    public ResponseVO processXML()
        throws Exception
    {
        strReqType = getReqType();
        if(strReqType.equals(RequestTypeConst.BOCI_BALANCE_URL) || strReqType.equals(RequestTypeConst.BOCI_BALANCE_V2_URL))
            return processBalanceV2XML();
        else
            return null;
    }

    public ArrayList transformVOList(NodeList pNodeList)
    {
        int nodeLength = pNodeList.getLength();
        ArrayList list = new ArrayList();
        for(int i = 0; i < nodeLength; i++)
        {
            BalanceDetailVO balanceDetailVO = new BalanceDetailVO(strReqType, strRtnCode);
            Element element = (Element)pNodeList.item(i);
            String currency = getAttrValue(element, "CURRENCY");
            String tradeDateBalance = getNodeValue(element, "TRADE_DATE_BALANCE");
            String settlementDateBalance = getNodeValue(element, "SETTLEMENT_DATE_BALANCE");
            String marketValue = getNodeValue(element, "MARKET_VALUE");
            String portfolioValue = getNodeValue(element, "PORTFOLIO_VALUE");
            String buyingPower = getNodeValue(element, "BUYING_POWER_QUALIFIED_SEC");
            String investmentPower = getNodeValue(element, "INVESTMENT_POWER");
            balanceDetailVO.setCurrency(currency);
            balanceDetailVO.setTradeDateBalance(tradeDateBalance);
            balanceDetailVO.setSettlementDateBalance(settlementDateBalance);
            balanceDetailVO.setMarketValue(marketValue);
            balanceDetailVO.setPortfolioValue(portfolioValue);
            balanceDetailVO.setBuyingPower(buyingPower);
            balanceDetailVO.setInvestmentPower(investmentPower);
            list.add(balanceDetailVO);
        }

        return list;
    }

    public ResponseVO processBalanceV2XML()
    {
        strReqType = getReqType();
        strRtnCode = getReturnCode();
        BalanceVO balanceVO = new BalanceVO(strReqType, strRtnCode);
        NodeList conCashHoldList = resultDocument.getElementsByTagName("CONSOLIDATED_CASH_HOLDING");
        ArrayList conBalanceDetailVOList = transformVOList(conCashHoldList);
        balanceVO.setConBalanceDetailVOList(conBalanceDetailVOList);
        NodeList cashHoldList = resultDocument.getElementsByTagName("CASH_HOLDING");
        ArrayList balanceDetailVOList = transformVOList(cashHoldList);
        balanceVO.setBalanceDetailVOList(balanceDetailVOList);
        return balanceVO;
    }

    String strRtnCode;
    String strReqType;
}
